Repository navigation
Fix CPU MoE input corruption from in-place buffer reuse - #33885
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the CPU MoE buffer-aliasing fix.
No open issues 🎉
What changed in this PR
Fixes CPU MoE input corruption when its output reuses token storage, addressing #33866 without tying buffer preservation to routing-weight normalization.
Changes:
- Copies tokens before clearing the output when input and output buffers alias.
- Adds float32 and float16 regression tests covering graph inputs,
AddandReshape(Add)producers, intermediate and exposed MoE outputs, both normalization modes, and repeated runs.
| File | Description |
|---|---|
| onnxruntime/test/contrib_ops/moe_test.cc | Adds regression coverage for CPU MoE buffer reuse across graph configurations. |
| onnxruntime/contrib_ops/cpu/moe/moe_cpu.cc | Preserves tokens whenever input and output buffers alias. |
Review effort: Balanced
Bring the SentencePiece 0.2.2 pin compatible with CI's protobuf 6.x runtime and refresh current-main validation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Akshay Sonawane (apsonawane)
left a comment
There was a problem hiding this comment.
AI-assisted source review at 297d797120f54556a7ad2eb8e21a365252f0dad9.
Checked the in-place allocation contract, the ordering of token preservation and output clearing, all subsequent FP32/FP16 input reads, and the added producer/output/normalization/repeated-run regressions. The preservation condition now follows actual buffer aliasing rather than routing normalization, while non-aliased inputs avoid the unnecessary copy.
No new actionable findings in this pass. An isolated numerical model passed alias/non-alias cases with normalization on/off; this was not execution of the ORT kernel or regression suite. The reported head checks are 100 successful and one neutral. No local native build was run.
Tianlei Wu (tianleiwu)
left a comment
There was a problem hiding this comment.
Reviewed the CPU MoE alias-preservation fix at 297d797120f54556a7ad2eb8e21a365252f0dad9. No actionable findings.
Copying only when input/output pointers alias matches the in-place registration and preserves tokens before output clearing, independently of routing normalization. Both float and half consumers use the preserved pointer. The graph-level regressions cover graph inputs, Add intermediates and Reshape aliases, exposed/hidden MoE output, normalization on/off, both dtypes, and repeated use of the same feeds.
Exact-head CPU/native CI is green, including Linux Release/ASan and ARM64 configurations. No local native build or test run was performed. Comment-only review; no approval submitted.
Description
AddandReshape(Add)producers, intermediate/exposed MoE outputs, and both normalization modes.Motivation and Context
CPU
MoEcan return incorrect results inAdd → MoE → Reluwhen routing normalization is disabled. Its in-place allocation contract permits output to reuse token storage, but clearing that output destroys tokens before expert computation reads them.MoEgives wrong results when its input is computed in the graph and its output feeds another node #33866